package miage.rest.resource.mail;

import org.restlet.data.ChallengeScheme;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.resource.ClientResource;

/**
 *
 * @author Schwartz Michaël
 */
public class MailClientResourceFactory {


	private final String smtpHost;
	private final int smtpPort;
	private final String smtpUser;
	private final String smtpPassword;


	public MailClientResourceFactory(	String smtpHost,
										int smtpPort,
										String smtpUser,
										String smtpPassword) {

		this.smtpHost = smtpHost;
		this.smtpPort = smtpPort;
		this.smtpUser = smtpUser;
		this.smtpPassword = smtpPassword;

	}

	public ClientResource create() {

		ClientResource client = new ClientResource(new Reference(Protocol.SMTP,
																 smtpHost,
																 smtpPort));
		if (smtpUser != null && smtpPassword != null) {
			client.setChallengeResponse(ChallengeScheme.SMTP_PLAIN,
										smtpUser,
										smtpHost);
		}

		return client;
	}
}
